﻿!function ($) {
    $(function() {
        window.prettyPrint && prettyPrint();

        // Show JS specific content.
        $('.js').show()
            .removeClass('js');

        $('.alert').alert();
        $('.watermark').watermark();

        // Submit the parent form when a select control is updated.
        $('select.change-submit').each(function() {
            var $select = $(this);
            var $form = $select.parent('form:first');

            $select.change(function() {
                $form.submit();
            });

            $form.find('button, input[type=submit]').remove();
        });

        var $navbar = $('.navbar-fixed-top');
        var offsetTop = 0;
        
        if ($navbar.length) {
             offsetTop = $navbar.height();
        }

        // Scroll to the first error.
        $('html, body').animate({
            scrollTop: $('.alert-error:first').offset().top - offsetTop
        }, 1000);
    })
}(window.jQuery)